﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebHousingInfo.Controls
{
    public partial class DuBaoThoiTiet : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                try
                {

                    LoadData("http://vnexpress.net/ListFile/Weather/hanoi.xml");

                }

                catch
                {
                }
            }
        }
        // Hàm bind dữ liệu xml ra DataTable

        private DataTable GetTable(string FileName)
        {

            DataTable dtb = new DataTable();

            DataSet authorsDataSet;

            string filePath = FileName;

            authorsDataSet = new DataSet();



            authorsDataSet.ReadXml(filePath);

            dtb = authorsDataSet.Tables[0];

            return dtb;

            //GridView1.DataSource = authorsDataSet.Tables[0].DefaultView;

            //GridView1.DataBind();

        }

        // Load dữ liệu theo filepath

        private void LoadData(string xmlFilePath)
        {

            DataTable dtb = GetTable(xmlFilePath);

            if (dtb.Rows.Count > 0)
            {

                Literal1.Text = "&nbsp;<img src='http://vnexpress.net/Images/Weather/" + dtb.Rows[0][0].ToString().Trim() + "'>";

                Literal1.Text += "<img src='http://vnexpress.net/Images/Weather/" + dtb.Rows[0][1].ToString().Trim() + "'>";

                Literal1.Text += "<img src='http://vnexpress.net/Images/Weather/" + dtb.Rows[0][2].ToString().Trim() + "'>";

                Literal1.Text += "<img src='http://vnexpress.net/Images/Weather/c.gif'>";

                Literal1.Text += "<br>" + dtb.Rows[0][6].ToString().Trim();

            }

            dtb.Dispose();

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

            LoadData("http://vnexpress.net/ListFile/Weather/" + DropDownList1.SelectedValue.ToString());

        }

    }
}